$(function () {
    data.deptId = $("#id").val();
    data.title = "【" + $("#name").val() + "】用户"
    //加载表格数据
    methods.getTableData();
});

var data = {
    title: "",
    deptId: "",
    //分页
    paging: {
        currentPage: 1,
        pageSize: 10,
        total: 11,
        tableData: []
    },
    //搜索
    search: {}
};

var methods = {
    //移除用户部门
    removeUserDept: function (row) {
        layer.confirm("您确定将【" + row.nickname + "】移出此部门吗？", function (index) {
            layer.close(index);
            ajax.post("/system/user/deleteUserDept", {
                userId: row.id,
                removeDeptId: data.deptId
            }, function (res) {
                layer.msg(res.msg);
                methods.getTableData();
            })
        })
    },
    //搜索用户
    searchUser: function () {
        data.paging.currentPage = 1;
        methods.getTableData();
    },
    //添加或保存
    saveOrUpdate: function () {
        data.dialog.loading = true;
        setTimeout(function () {
            data.dialog.show = false;
        }, 1000)
    },
    //获取表格数据
    getTableData: function () {
        var load = layer.load(2);
        ajax.post("/system/user/getUserList", {
            deptId: data.deptId,
            sContent: data.search.sContent,
            currentPage: data.paging.currentPage,
            pageSize: data.paging.pageSize
        }, function (res) {
            layer.close(load);
            var tableData = res.data.rows;
            data.paging.tableData = tableData;
            data.paging.total = res.data.total;
        })

    },
    //处理页面大小变化
    handleSizeChange: function (val) {
        data.paging.pageSize = val;
        data.paging.currentPage = 1;
        methods.getTableData();
    },
    //处理当前页面变化
    handleCurrentChange: function (val) {
        data.paging.currentPage = val;
        methods.getTableData();
    },
    //处理对话框关闭
    handleDialogClose: function () {
        data.dialog.loading = false;
        data.dialog.disabled = false;
        data.dialog.title = "信息";
        data.currentObj = {};
    },
    //关闭对话框
    closeDialog: function () {
        if (parent) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index)
        } else {
            layer.closeAll();
        }
    }

};
var vm = new Vue({data: data, methods: methods}).$mount("#app");
